package com.cmb.locker;

import java.util.HashMap;
import java.util.Map;

public class Locker {

    private final int capacity;
    private final Map<Ticket, Bag> bags = new HashMap<>();

    public Locker(int capacity) {
        this.capacity = capacity;
    }

    public Ticket save(Bag bag) throws LockerIsFullException {
        if (bags.size() == capacity) {
            throw new LockerIsFullException();
        }
        Ticket ticket = new Ticket();
        bags.put(ticket, bag);
        return ticket;
    }

    public Bag getBag(Ticket ticket) throws InvalidTicketException {
        if (bags.containsKey(ticket)) {
           return bags.remove(ticket);
        }
        throw new InvalidTicketException();
    }
}
